package com.syq.service.impl;

import com.syq.constant.StrategyConstants;
import com.syq.dfa.SensitiveWordFilter;
import com.syq.model.StandardSubmit;
import com.syq.service.FilterChainService;
import com.syq.util.PushMsgUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName: DirtyWordsFilterServiceImpl
 * @Description: TODO
 * @Create by: syq
 * @Date: 2022/8/27 9:51
 */

@Service("dirtyWords")
@Slf4j
public class DirtyWordsFilterServiceImpl implements FilterChainService {
    @Autowired
    private PushMsgUtil pushMsgUtil;

    @Override
    public boolean strategy(StandardSubmit standardSubmit) {
        System.out.println("敏感词");
        String messageContent = standardSubmit.getMessageContent();
        SensitiveWordFilter instance = SensitiveWordFilter.getInstance();
        int count = instance.checkSensitiveWord(messageContent, 0, SensitiveWordFilter.maxMatchType);
        if (count>0){
            pushMsgUtil.sendLog(standardSubmit, StrategyConstants.STRATEGY_ERROR_DIRTY_WORDS);
            pushMsgUtil.pushReport(standardSubmit,StrategyConstants.STRATEGY_ERROR_DIRTY_WORDS);
            log.error("有敏感词");
            return false;
        }
        return true;
    }
}
